//
//  HSOrderMoreCell.m
//  hsdyOrderSystem
//
//  Created by XunFengKJ on 2017/11/13.
//  Copyright © 2017年 赖国锋. All rights reserved.
//

#import "HSOrderMoreCell.h"

@implementation HSOrderMoreCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.readyUpBtn.layer.cornerRadius = 15;
    self.lookDetailBtn.layer.cornerRadius = 15;
    self.pictureScrollView.alwaysBounceHorizontal = YES;
    self.pictureScrollView.alwaysBounceVertical = NO;
    self.pictureScrollView.showsHorizontalScrollIndicator = YES;
    self.pictureScrollView.showsVerticalScrollIndicator = NO;
}

-(void)setModel:(HSOrderModel *)model{
    _model = model;
    self.lookDetailBtn.tag = [model.outTradeNo integerValue];
    self.readyUpBtn.tag = [model.outTradeNo integerValue];
    self.orderNumLabel.text = [NSString stringWithFormat:@"下单用户:%@",model.wxUserPhone.length?model.wxUserPhone:@"暂无相关信息"];
    NSString *tableCount = [NSString stringWithFormat:@"%@",model.tableNumber];
    self.tableNumberL.text = [NSString stringWithFormat:@"桌位号:%@",tableCount.length?tableCount:@"暂无"];
    
    if (model.isShowComingtime) {
        self.orderTimeLabel.text =[NSString stringWithFormat:@"到店时间:%@",[NSString timeWithTimeIntervalString:model.reservationTime]];
    }else{
        self.orderTimeLabel.text =[NSString stringWithFormat:@"下单时间:%@",[NSString timeWithTimeIntervalString:model.createTime]];
    }
    self.readyUpBtn.hidden = !model.isHaveReadyUpBtn;//是否隐藏已上菜按钮
    
    NSInteger shopCount = 0;
    [self.imagesArr removeAllObjects];
    for (HSOrderDetailModel *detailM in model.foodsList) {
        shopCount = shopCount + [detailM.shopCount integerValue];
        [self.imagesArr addObject:detailM.foodsImage];
    }
    self.totalL.text =  [NSString stringWithFormat:@"共%zd件商品，总计：%.2f",shopCount,[self roundFloat:[[NSString stringWithFormat:@"%@",model.totalPay] floatValue]]];
    [self setUpScrollView];
}

-(void)setUpScrollView{
    CGFloat height = 110;
    for (int i =0; i<self.imagesArr.count; i++) {
        //创建一个视图
        UIImageView *pImageView = [[UIImageView alloc]initWithFrame:CGRectMake(i*(height+10) , 0, height, height)];
        //设置imageView的背景图
//        LGFLog(@"设置imageView的背景图   == == = %@",self.imagesArr[i]);
        [pImageView sd_setImageWithURL:[NSURL URLWithString:self.imagesArr[i]] placeholderImage:nil];
        //设置图片内容的显示模式(自适应模式)
        pImageView.contentMode = UIViewContentModeScaleAspectFit;
        //把视图添加到当前的滚动视图中
        [self.pictureScrollView addSubview:pImageView];
    }
    [self.pictureScrollView setContentSize:CGSizeMake(self.imagesArr.count*(height+10) , 0)];
}

//除100区两位小数
-(float)roundFloat:(float)price{
    return  round(price * 100) / 10000;
}
//查看订单
- (IBAction)checkOrderBtnClick:(UIButton*)sender {
    if (self.DetailBtnBlock) {
        self.DetailBtnBlock(sender.tag);
    }
}
//完成订单
- (IBAction)compareOrderBtnClick:(UIButton*)sender {
    if (self.CompleteBtnBlock) {
        self.CompleteBtnBlock(sender.tag);
    }
}

-(NSMutableArray *)imagesArr{
    if (!_imagesArr) {
        _imagesArr = @[].mutableCopy;
    }
    return _imagesArr;
}

@end
